package com.hq.api;


import com.hq.dao.HomeDao;
import com.hq.dao.Staff_messageDao;
import com.hq.pojo.Staff;
import com.hq.pojo.Staff_message;
import com.hq.utils.MassageJson;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/staff_m")
public class Staff_messageApi {


    @Resource
    Staff_messageDao staff_messageDao;

    @Resource
    HomeDao homeDao;

    //添加员工
        @RequestMapping(value = "/add_staff",method = RequestMethod.POST)
    public MassageJson add_staff(@RequestBody Staff staff){
        int i= 0;
        try {
            System.out.println(staff);
            if(staff!=null){
                
                i = staff_messageDao.add_staff(staff);
            }else {
                return new MassageJson(203,"空数据",i);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        if(i!=0){
            return new MassageJson(200,"添加成功",i);
        }else {

            return new MassageJson(201,"添加失败",i);
        }
    }

    //添加员工信息
    @RequestMapping(value = "/add_staff_message",method = RequestMethod.POST)
    public MassageJson add_staff_message(@RequestBody Staff_message staff_message){
        int i= 0;
        try {
            System.out.println(staff_message);
            if(staff_message!=null){
                i = staff_messageDao.add_staff_message(staff_message);
            }else {
                return new MassageJson(203,"空数据",i);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        if(i!=0){
            return new MassageJson(200,"添加成功",i);
        }else {

            return new MassageJson(201,"添加失败",i);
        }
    }

    //删除员工信息
    @RequestMapping(value = "/del_staff",method = RequestMethod.GET)
    public MassageJson del_staff(Integer id){
        int i = 0;
        try{
            System.out.println("删除员工信息的ID"+id);
            if (id!=0){
                i = staff_messageDao.del_staff(id);
            }else {
                return new MassageJson(203,"空数据",i);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        if(i!=0){
            return new MassageJson(200,"删除成功",i);
        }else {
            return new MassageJson(201,"删除失败",i);
        }
        
    }
    
    //改员工数据
    @RequestMapping(value = "/upd_staff",method = RequestMethod.POST)
    public MassageJson upd_staff(@RequestBody Staff staff){
        int i = 0;
        try{
            System.out.println("要修改的员工"+staff);
            i = staff_messageDao.upd_staff(staff);
        }catch (Exception e){
            e.printStackTrace();
        }
        if(i!=0){
            return new MassageJson(200,"修改成功",i);
        }else {
            return new MassageJson(201,"修改失败",i);
        }
        
    }

    //改员工信息数据
    @RequestMapping(value = "/sel_staff_message",method = RequestMethod.POST)
    public MassageJson sel_staff_message(@RequestBody Staff_message staff_message){
        int i = 0;
        try{
            System.out.println("要修改的员工信息"+staff_message);
            i = staff_messageDao.upd_staff_message(staff_message);
        }catch (Exception e){
            e.printStackTrace();
        }
        if(i!=0){
            return new MassageJson(200,"修改成功",i);
        }else {
            return new MassageJson(201,"修改失败",i);
        }

    }


    //查询员工信息
    @RequestMapping(value = "/Staff_message_list_all",method = RequestMethod.POST)
    public MassageJson Staff_message_list_all(Integer pages,Integer pageSize,String inquire){
        System.out.println("所接到的 pages 是"+pages);
        System.out.println("所接到的 pageSize 是"+pageSize);
        System.out.println("所接到的 inquire 是"+inquire);
        List<Staff_message> stafflist = null;
        try {

            //int start=(pages-1) * pageSize;
            //stafflist = staff_messageDao.Staff_message_list_all(start,pageSize,inquire);
            stafflist = staff_messageDao.Staff_message_list_all(0,500,inquire);
            if(stafflist!=null){
                //返回查询数据，返回总条数
                //return new MassageJson(200,"请求成功",stafflist,xxxDao.gets(inquire));
                return new MassageJson(200,"请求成功",stafflist,homeDao.getStaff_Counts());
            }
            
        }catch (Exception e){
            e.printStackTrace();
        }
        return new MassageJson(201,"请求失败",stafflist,0);
    }







}
